package com.rdc.dictionary.mvpBase;

import com.rdc.dictionary.mvpPresenters.MvpPresenter;

/**
 * @author Soul Mate
 * @file 文件名
 * @brief 用于控制MvpPresenter与MvpView
 */

public class MvpInternalDelegate<P extends MvpPresenter, V extends MvpView> {
	BaseDelegateCallback<P, V> callback;

	public MvpInternalDelegate(BaseDelegateCallback<P, V> callback) {
		this.callback = callback;
	}


	public P createPresenter()
	{
		P p = callback.getPresenter();
		if (p == null)
			p = callback.createPresenter();
		if (p == null)
			throw new NullPointerException("创建presenter失败请检查！");
		return p;
	}

	public void attachView()
	{
		callback.getPresenter().attachView(callback.getMvpView());
	}

	public void detachView()
	{
		callback.getPresenter().detachView();
	}
}
